const Custom = ({ midder, hook, Tree }) => {
	const { proxy } = midder;
	const { useState, createElement } = hook.$m;
	const { columns = [] } = proxy;
	let baseData = [...columns];
	const [gData, setGData] = useState(baseData);
	const onDrop = (info) => {
		const { dropPosition, dragNodesKeys } = info;
		const dragIdx = baseData.findIndex((item) => item.key === dragNodesKeys[0]);
		const arr = baseData.splice(dragIdx, 1);
		if (dropPosition === -1) {
			console.log('拖拽到最顶部');
			baseData = [...arr, ...baseData];
		} else if (dropPosition > dragIdx) {
			console.log('从上往下拖拽');
			baseData = [...baseData];
			baseData.splice(dropPosition - 1, 0, ...arr);
		} else {
			console.log('从下往上拖拽');
			baseData = [...baseData];
			baseData.splice(dropPosition, 0, ...arr);
		}
		setGData(baseData);
		proxy.columns = baseData;
	};
	return createElement(Tree, {
		defaultCheckedKeys: baseData.filter((item) => !item.hidden).map((item) => item.key),
		checkable: true,
		draggable: true,
		blockNode: true,
		onDrop,
		treeData: gData,
		onCheck: (keys) => {
			proxy.columns = baseData.map((item) => {
				item.hidden = !keys.includes(item.key);
				return item;
			});
		}
	});
};
export default Custom;